﻿//
// Decompiled with: Decompiler.NET, Version=1.3.1.18439, Culture=neutral, PublicKeyToken=null, Version: 1.3.1.18439
// Decompilation Started at: 3/15/2009 10:34:26 PM
// Copyright 2003 - 2004, Jungle Creatures, Inc., All Rights Reserved. 
// Written by Jonathan Pierce, Email: support@junglecreatures.com
//

namespace PatientManagement

{
		
		#region Namespace Import Declarations
		
			using System.ComponentModel;
			using System.Data.Common;
			using System.Data;
			using System.Data.SqlClient;
			using System.Drawing;
			using System;
			using System.Resources;
			using System.Windows.Forms;
			using Utility;
			
		#endregion
		
	public class frmDangNhap : Form
	
	{
		
		#region Fields
			private frmMain _parent;
			private Button btExit;
			private Button btLogin;
			private Container components;
			private string connStr;
			private int count;
			private Database_Com db;
			private Label label1;
			private Label label2;
			private Label label3;
			private TextBox tbPassword;
			private TextBox tbUserName;
			public string user;
		#endregion
		
		#region Constructors
		
			public frmDangNhap (frmMain parent)
			
			{
				this.components = ((System.ComponentModel.Container) null);
				this.db = new Database_Com ();
				this.count = 0;
				this._parent = parent;
				this.InitializeComponent ();
				this.connStr = Connection.ConnectionString ();
				return;
			}
			
		#endregion
		
		#region Methods
		
			private void btExit_Click (object sender, EventArgs e)
			
			{
				this._parent.mnuBaoCao.Enabled = false;
				this._parent.mnuNhanVien.Enabled = false;
				this._parent.mnuCapQuyen.Enabled = false;
				this._parent.mnuThayDoi.Enabled = false;
				this._parent.mnuLapBenhAn.Enabled = false;
				this._parent.mnuDangNhap.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = false;
				this._parent.btnBaoCao.Enabled = false;
				this._parent.btnLapBenhAnMoi.Enabled = false;
				this._parent.btnTimHSBenhAn.Enabled = false;
				this._parent.mnuTienIch.Enabled = false;
				this._parent.mnuHoaDon.Enabled = false;
				base.Close ();
				return;
			}
			
			private void btLogin_Click (object sender, EventArgs e)
			
			{
				string theString;
				SqlDataAdapter theSqlDataAdapter;
				DataSet theDataSet;
				int i;
				Class theClass;
				string theString2;
				string theString3;
				string theString4;
				Class theClass2;
				SqlConnection theSqlConnection;
				SqlDataAdapter theSqlDataAdapter2;
				DataSet theDataSet2;
				DataTable theDataTable;
				string theString5;
				int i2;
				string[] theStringArray;
				theString = "SELECT * FROM Users ";
				theSqlDataAdapter = new SqlDataAdapter (theString, this.connStr);
				theDataSet = new DataSet ();
				i = theSqlDataAdapter.Fill (theDataSet);
				if (i != 0)
				{
					goto L_006F;
				}
				SqlConnection theSqlConnection2 = this.db.CreateConnections ();
				theClass = new Class ();
				theString2 = "sa";
				theString2 = theClass.Encrypt (theString2);
				theString3 = string.Concat ("INSERT INTO Users VALUES(\'sa\', \'", theString2, "\',0)");
				int i3 = this.db.Excu_NonQuery (theString3);
				goto L_0B61;
				
			L_006F:
				
				{
				}
				if (! this.tbUserName.Text.Equals (""))
				{
					goto L_00AA;
				}
                DialogResult theDialogResult = MessageBox.Show("Vui lòng nhập tên Đăng Nhập!", "Lỗi Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				bool theBoolean = this.tbUserName.Focus ();
				goto L_0B61;
				
			L_00AA:
				
				{
				}
				if (! this.tbPassword.Text.Equals (""))
				{
					goto L_00E5;
				}
                DialogResult theDialogResult2 = MessageBox.Show("Vui lòng nhập Mật Khẩu!", "Lỗi Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				bool theBoolean2 = this.tbPassword.Focus ();
				goto L_0B61;
				
			L_00E5:
				
				{
				}
				theString4 = this.tbPassword.Text.ToString ();
				theClass2 = new Class ();
				theString4 = theClass2.Encrypt (theString4);
				theSqlConnection = new SqlConnection (this.connStr);
				theStringArray = new string[5];
				theStringArray[0] = "SELECT usrRole FROM Users WHERE usrName=\'";
				theStringArray[1] = this.tbUserName.Text.Trim ();
				theStringArray[2] = "\' AND usrPassword=\'";
				theStringArray[3] = theString4;
				theStringArray[4] = "\'";
				theSqlDataAdapter2 = new SqlDataAdapter (string.Concat (theStringArray), theSqlConnection);
				theDataSet2 = new DataSet ();
				int i4 = theSqlDataAdapter2.Fill (theDataSet2, "Users");
				if ((theDataSet2 != null) && ((theDataSet2.Tables.Count != 0) && (theDataSet2.Tables[0].Rows.Count != 0)))
				{
					goto L_01EB;
				}
				
			L_01A4:
				
				{
				}
                DialogResult theDialogResult3 = MessageBox.Show("Tên Đăng Nhập hoặc Mật Khẩu không hợp lệ!", "Lỗi Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.count++;
				if (this.count != 3)
				{
					goto L_01E6;
				}
                DialogResult theDialogResult4 = MessageBox.Show("Bạn đã đăng nhập 3 lần không hợp lệ \n", "Đăng nhập không hợp lệ?", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				Application.Exit ();
				
			L_01E6:
				
				{
				}
				goto L_0B61;
				
			L_01EB:
				
				{
				}
				this.user = this.tbUserName.Text;
				theDataTable = theDataSet2.Tables["Users"];
				theString5 = theDataTable.Rows[0][0].ToString ();
				if (theString5 != "0")
				{
					goto L_049C;
				}
				this._parent.mnuBaoCao.Enabled = true;
				this._parent.mnuBS.Enabled = true;
				this._parent.mnuCapQuyen.Enabled = true;
				this._parent.mnuQuyen.Enabled = true;
				this._parent.mnuNhanVien.Enabled = true;
				this._parent.mnuThuoc.Enabled = true;
				this._parent.mnuXoaBenhAn.Enabled = true;
				this._parent.mnuHD.Enabled = true;
				this._parent.mnuDangNhap.Enabled = true;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuLapToaThuoc.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = true;
				this._parent.ctmCuoiThang.Enabled = true;
				this._parent.ctmTheoBacSi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = true;
				this._parent.mnuHoaDon.Enabled = true;
				this._parent.mnuBaoCao.Enabled = true;
				this._parent.mnuNhanVien.Enabled = true;
				this._parent.mnuCapQuyen.Enabled = true;
				this._parent.mnuDangNhap.Enabled = false;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = true;
				this._parent.btnLapBenhAnMoi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = true;
				this._parent.mnuHoaDon.Enabled = true;
				UserInformation.usrRole = "1";
				goto L_0B02;
				
			L_049C:
				
				{
				}
				if (theString5 != "1")
				{
					goto L_070F;
				}
				this._parent.mnuBaoCao.Enabled = true;
				this._parent.mnuBS.Enabled = true;
				this._parent.mnuCapQuyen.Enabled = true;
				this._parent.mnuQuyen.Enabled = true;
				this._parent.mnuNhanVien.Enabled = true;
				this._parent.mnuThuoc.Enabled = true;
				this._parent.mnuXoaBenhAn.Enabled = true;
				this._parent.mnuHD.Enabled = true;
				this._parent.mnuDangNhap.Enabled = true;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuLapToaThuoc.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = true;
				this._parent.ctmCuoiThang.Enabled = true;
				this._parent.ctmTheoBacSi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = true;
				this._parent.mnuHoaDon.Enabled = true;
				this._parent.mnuBaoCao.Enabled = false;
				this._parent.mnuNhanVien.Enabled = false;
				this._parent.mnuCapQuyen.Enabled = false;
				this._parent.mnuDangNhap.Enabled = false;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = false;
				this._parent.btnLapBenhAnMoi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = true;
				this._parent.mnuHoaDon.Enabled = false;
				UserInformation.usrRole = "1";
				goto L_0B02;
				
			L_070F:
				
				{
				}
				if (theString5 != "2")
				{
					goto L_0982;
				}
				this._parent.mnuBaoCao.Enabled = true;
				this._parent.mnuBS.Enabled = true;
				this._parent.mnuCapQuyen.Enabled = true;
				this._parent.mnuQuyen.Enabled = true;
				this._parent.mnuNhanVien.Enabled = true;
				this._parent.mnuThuoc.Enabled = true;
				this._parent.mnuXoaBenhAn.Enabled = true;
				this._parent.mnuHD.Enabled = true;
				this._parent.mnuDangNhap.Enabled = true;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuLapToaThuoc.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = true;
				this._parent.ctmCuoiThang.Enabled = true;
				this._parent.ctmTheoBacSi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = true;
				this._parent.mnuHoaDon.Enabled = true;
				this._parent.mnuBaoCao.Enabled = false;
				this._parent.mnuNhanVien.Enabled = false;
				this._parent.mnuCapQuyen.Enabled = false;
				this._parent.mnuDangNhap.Enabled = false;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = true;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = false;
				this._parent.btnLapBenhAnMoi.Enabled = true;
				this._parent.btnTimHSBenhAn.Enabled = true;
				this._parent.mnuTienIch.Enabled = false;
				this._parent.mnuHoaDon.Enabled = false;
				UserInformation.usrRole = "0";
				goto L_0B02;
				
			L_0982:
				
				{
				}
				this._parent.mnuBaoCao.Enabled = true;
				this._parent.mnuBS.Enabled = false;
				this._parent.mnuCapQuyen.Enabled = true;
				this._parent.mnuQuyen.Enabled = false;
				this._parent.mnuNhanVien.Enabled = false;
				this._parent.mnuThuoc.Enabled = true;
				this._parent.mnuXoaBenhAn.Enabled = false;
				this._parent.mnuHD.Enabled = false;
				this._parent.mnuDangNhap.Enabled = false;
				this._parent.mnuThayDoi.Enabled = true;
				this._parent.mnuLapBenhAn.Enabled = true;
				this._parent.mnuLapBenhAnMoi.Enabled = false;
				this._parent.mnuLapToaThuoc.Enabled = true;
				this._parent.mnuTimHSBenhAn.Enabled = false;
				this._parent.mnuDoiMatKhau.Enabled = true;
				this._parent.btnBaoCao.Enabled = true;
				this._parent.ctmCuoiThang.Enabled = true;
				this._parent.ctmTheoBacSi.Enabled = false;
				this._parent.btnLapBenhAnMoi.Enabled = false;
				this._parent.btnTimHSBenhAn.Enabled = false;
				this._parent.mnuTienIch.Enabled = false;
				this._parent.mnuHoaDon.Enabled = true;
				UserInformation.usrRole = "3";
				
			L_0B02:
				
				{
				}
				theSqlDataAdapter2.Dispose ();
				theSqlConnection.Close ();
				SqlConnection theSqlConnection3 = this.db.CreateConnections ();
				i2 = ((int) this.db.ExecuteScalar (string.Concat ("select usrISN from Users where usrName = \'", this.user, "\'")));
				Class.name = this.user;
				Class.isn = i2.ToString ();
				base.Close ();
				
			L_0B61:
				return;
			}
			
			protected override void Dispose (bool disposing)
			
			{
				if (! disposing)
				{
					goto L_0016;
				}
				if (this.components == null)
				{
					goto L_0016;
				}
				this.components.Dispose ();
				
			L_0016:
				
				{
				}
				base.Dispose (disposing);
				return;
			}
			
			private void frmDangNhap_Load (object sender, EventArgs e)
			
			{
				return;
			}
			
			private void InitializeComponent ()
			
			{
				ResourceManager theResourceManager;
				Control[] theControlArray;
				theResourceManager = new ResourceManager (typeof (frmDangNhap));
				this.label1 = new Label ();
				this.label2 = new Label ();
				this.tbUserName = new TextBox ();
				this.tbPassword = new TextBox ();
				this.label3 = new Label ();
				this.btLogin = new Button ();
				this.btExit = new Button ();
				base.SuspendLayout ();
				this.label1.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.label1.Location = new Point (24, 64);
				this.label1.Name = "label1";
				this.label1.Size = new System.Drawing.Size (112, 23);
				this.label1.TabIndex = 0;
				this.label1.Text = "Tên Truy Nhập:";
				this.label2.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.label2.Location = new Point (24, 96);
				this.label2.Name = "label2";
				this.label2.TabIndex = 1;
				this.label2.Text = "Mật Khẩu:";
				this.tbUserName.BorderStyle = BorderStyle.FixedSingle;
				this.tbUserName.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.tbUserName.Location = new Point (136, 64);
				this.tbUserName.Name = "tbUserName";
				this.tbUserName.Size = new System.Drawing.Size (184, 23);
				this.tbUserName.TabIndex = 2;
				this.tbUserName.Text = "";
				this.tbUserName.KeyPress += new KeyPressEventHandler (this.tbUserName_KeyPress);
				this.tbPassword.BorderStyle = BorderStyle.FixedSingle;
				this.tbPassword.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.tbPassword.Location = new Point (136, 96);
				this.tbPassword.Name = "tbPassword";
				this.tbPassword.PasswordChar = '\u002A';
				this.tbPassword.Size = new System.Drawing.Size (184, 23);
				this.tbPassword.TabIndex = 3;
				this.tbPassword.Text = "";
				this.tbPassword.KeyPress += new KeyPressEventHandler (this.tbPassword_KeyPress);
				this.label3.Font = new System.Drawing.Font ("Verdana", 12F, FontStyle.Bold, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.label3.ForeColor = Color.MediumBlue;
				this.label3.Location = new Point (80, 16);
				this.label3.Name = "label3";
				this.label3.Size = new System.Drawing.Size (208, 23);
				this.label3.TabIndex = 4;
                this.label3.Text = "Đăng Nhập Hệ Thống";
				this.btLogin.FlatStyle = FlatStyle.Popup;
				this.btLogin.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.btLogin.Location = new Point (136, 128);
				this.btLogin.Name = "btLogin";
				this.btLogin.Size = new System.Drawing.Size (96, 23);
				this.btLogin.TabIndex = 5;
                this.btLogin.Text = "Đăng Nhập";
				this.btLogin.Click += new EventHandler (this.btLogin_Click);
				this.btExit.FlatStyle = FlatStyle.Popup;
				this.btExit.Font = new System.Drawing.Font ("Verdana", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				this.btExit.Location = new Point (245, 128);
				this.btExit.Name = "btExit";
				this.btExit.TabIndex = 6;
				this.btExit.Text = "Thoát";
				this.btExit.Click += new EventHandler (this.btExit_Click);
				this.AutoScaleBaseSize = new System.Drawing.Size (7, 15);
				base.ClientSize = new System.Drawing.Size (342, 163);
				theControlArray = new Control[7];
				theControlArray[0] = ((Control) this.btExit);
				theControlArray[1] = ((Control) this.btLogin);
				theControlArray[2] = ((Control) this.label3);
				theControlArray[3] = ((Control) this.tbPassword);
				theControlArray[4] = ((Control) this.tbUserName);
				theControlArray[5] = ((Control) this.label2);
				theControlArray[6] = ((Control) this.label1);
				base.Controls.AddRange (theControlArray);
				this.Font = new System.Drawing.Font ("Verdana", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte) byte.MinValue));
				base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
				base.Icon = ((System.Drawing.Icon) theResourceManager.GetObject ("$this.Icon"));
				base.MaximizeBox = false;
				base.MinimizeBox = false;
				base.Name = "frmDangNhap";
				base.StartPosition = FormStartPosition.CenterScreen;
                this.Text = "Đăng Nhập";
				base.Load += new EventHandler (this.frmDangNhap_Load);
				base.ResumeLayout (false);
				return;
			}
			
			private void tbPassword_KeyPress (object sender, KeyPressEventArgs e)
			
			{
				if (e.KeyChar != '\r')
				{
					goto L_0012;
				}
				this.btLogin_Click (sender, ((EventArgs) e));
				
			L_0012:
				return;
			}
			
			private void tbUserName_KeyPress (object sender, KeyPressEventArgs e)
			
			{
				if (e.KeyChar != '\r')
				{
					goto L_0012;
				}
				this.btLogin_Click (sender, ((EventArgs) e));
				
			L_0012:
				return;
			}
			
		#endregion
	}
	
}

